import xadmin

from apps.organizations.models import City, Org, Teacher


class CityAdmin(object):
    """
    机构所属城市后台管理
    """
    list_display = ["name", "desc"]
    list_filter = ["desc", "addTime"]
    search_fields = ["name"]
    readonly_fields = ["addTime"]
    style_fields = {"desc": "ueditor"}
    relfield_style = "fk-ajax"
    ordering = ["addTime"]


class OrgAdmin(object):
    """
    课程机构后台管理
    # city__name 和city是有区别的
    """
    list_filter = ["city__name", "category", "desc", "addTime"]
    search_fields = ["name"]
    list_display = ["city","name","category","address","clickNum","favNum","courses","students"]
    relfield_style = "fk-ajax"
    ordering = ["addTime"]
    style_fields = {"desc": "ueditor"}
    readonly_fields = ["clickNum", "favNum", "students", "courses", "addTime"]


class TeacherAdmin(object):
    """
    机构教师后台管理
    """
    list_filter = ["org__name", "workYear", "points", "addTime"]
    search_fields = ["name"]
    list_display = ["org", "name", "workYear", "points"]
    relfield_style = "fk-ajax"
    ordering = ["addTime"]
    readonly_fields = ["clickNum", "favNum", "addTime"]


xadmin.site.register(Org, OrgAdmin)
xadmin.site.register(Teacher, TeacherAdmin)
xadmin.site.register(City, CityAdmin)

